<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>佣金设置</h4>
		<form class="form-horizontal" id="myform">
			<div class="form-group">
				<label for="level_1_brokerage" class="col-sm-2 control-label">一级分佣</label>
				<div class="col-sm-5">
					<div class="input-group">
						<input type="text" class="form-control" name="level_1_brokerage" id="level_1_brokerage" value="<{$rule['level_1_brokerage']}>" placeholder="一级分佣">
						<div class="input-group-addon">%</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label for="level_2_brokerage" class="col-sm-2 control-label">二级分佣</label>
				<div class="col-sm-5">
					<div class="input-group">
						<input type="text" class="form-control" name="level_2_brokerage" id="level_2_brokerage" value="<{$rule['level_2_brokerage']}>" placeholder="二级分佣">
						<div class="input-group-addon">%</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label for="level_3_brokerage" class="col-sm-2 control-label">三级分佣</label>
				<div class="col-sm-5">
					<div class="input-group">
						<input type="text" class="form-control" name="level_3_brokerage" id="level_3_brokerage" value="<{$rule['level_3_brokerage']}>" placeholder="三级分佣">
						<div class="input-group-addon">%</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label for="level_3_brokerage" class="col-sm-2 control-label">总代分佣</label>
				<div class="col-sm-5">
					<div class="input-group">
						<input type="text" class="form-control" name="agency" id="agency" value="<{$rule['agency']}>" placeholder="总代分佣">
						<div class="input-group-addon">%</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-default col-sm-2">保存</button>
				</div>
			</div>
		</form>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/validate/messages_zh.js"></script>
<script>
$(function(){
	
	$("#myform").validate({
		rules: {
			level_1_brokerage : {
				required : true
            },
            level_2_brokerage : {
				required : true
            },
            level_3_brokerage : {
				required : true
            },
			agency:{
				required : true
			}
		},
		messages: {
			
		},
		submitHandler : function(form){
			var level_1_brokerage = $("#level_1_brokerage");
			var level_2_brokerage = $("#level_2_brokerage");
			var level_3_brokerage = $("#level_3_brokerage");
			var agency             = $('#agency');
			agency                 = parseFloat(agency);
			
			if(level_1_brokerage !== ''){
				level_1_brokerage = parseFloat(level_1_brokerage);
			}
			if(level_2_brokerage !== ''){
				level_2_brokerage = parseFloat(level_2_brokerage);
			}
			if(level_3_brokerage !== ''){
				level_3_brokerage = parseFloat(level_3_brokerage);
			}
			if((level_1_brokerage+level_2_brokerage+level_3_brokerage + agency) > 100){
				layer.alert("三级佣金和总代佣金相加不能大于100",{icon: 2});
				return false;
			}
			if(agency == ''){
				layer.alert("总代佣金不能为空",{icon: 2});
			}
			
			
			var ajaxUrl = "<{:U('Admin/Commission/Index')}>";
			 $.post(ajaxUrl,$(form).serialize(),function(r){
    			if (r.error == 1){
    				layer.alert(r.errmsg,{icon: 2});
    			}else{
    				layer.alert(r.errmsg,{icon: 1});
    			}
    			return false;
    		});
        	return false
		}
	});
});
</script>

<include file="Public/footer" /> 